package cn.edu.scau.cmi.zhangjunjia.adapter;

import java.util.Collections;
import java.util.List;

import cn.edu.scau.cmi.zhangjunjia.adapter.*;


public class SortUtil {
	
	
	
    public List sort(List<Student>studentList,int low,int high) {
    	
    	
    	Student x,temp;
    	int m,n;
    	if(low>high) {
    		return studentList;
    	}
    	
    	m= low;
    	n= high;
    	
        temp = studentList.get(low);
        
        while(m<n) {
        	while(temp.getId()<= studentList.get(n).getId() && m<n) {
        		n--;
        	}
        	
        	while(temp.getId()>= studentList.get(m).getId() && m<n) {
        		m++;
        	}
        	
        	if(m<n) {
        		x=studentList.get(n);
        		studentList.set(n, studentList.get(m));
        		studentList.set(m,x);
        	}
        	
        }
        
        studentList.set(low, studentList.get(m));
        studentList.set(m,temp);
        
        sort( studentList ,low,n-1);
        sort( studentList, n+1,high);
        
        return studentList;
  }
}

